#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <string.h>

char* my_strstr(const char* haystack, const char* needle)
{
	char* haystack_start = haystack;
	char* needle_start = needle;
	while (*haystack)
	{
		haystack = haystack_start;
		int i = 0;
		for (i = 0; *(needle + i) != '\0';)
		{
			if (*(needle + i) == *(haystack + i) && *(needle + i + 1) == '\0')
				return needle_start;
			else if (*(needle + i) == *(haystack + i))
				i++;
			else
				break;
		}
		haystack_start++;
		needle = needle_start;
	}
	return NULL;
}

int main()
{
	char haystack1[10] = "abbcdef";
	char haystack2[10] = "abccdef";
	char haystack3[10] = "ab";
	char haystack4[10] = "bcd";
	char haystack5[10] = "bcf";
	char needle[10] = "bcd";
	printf("%s\n", my_strstr(haystack1, needle));
	printf("%s\n", my_strstr(haystack2, needle));
	printf("%s\n", my_strstr(haystack3, needle));
	printf("%s\n", my_strstr(haystack4, needle));
	printf("%s\n", my_strstr(haystack5, needle));
	return 0;
}